Ext.define('Admin.view.gooutQuery.GooutQueryViewController', {
    extend: Ext.app.ViewController,
    alias: 'controller.gooutQueryViewController',
    gooutGridPanelSearch: function (btn) {
        var searchField = this.lookupReference('gooutGridSearchField').getValue();
        var searchText = this.lookupReference('gooutGridSearchText').getValue();
        var searchStartTime = Ext.util.Format.date(this.lookupReference('gooutSearchForm-startTime').getValue(), 'Y-m-d');
        var searchEndTime = Ext.util.Format.date(this.lookupReference('gooutSearchForm-endTime').getValue(), 'Y-m-d');
        var store = Ext.getCmp('gooutQueryGrid').getStore();
        Ext.apply(store.proxy.extraParams, {
            name: '',
            dept: '',
            number: '',
            startTime: '',
            endTime: ''
        });
        if (searchStartTime != '' && searchEndTime != '') {
            if (searchField == 'name') {
                Ext.apply(store.proxy.extraParams, {
                    name: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }
            if (searchField == 'dept') {
                Ext.apply(store.proxy.extraParams, {
                    dept: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }
            if (searchField == 'number') {
                Ext.apply(store.proxy.extraParams, {
                    number: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }
        } else {
            if (searchField == 'name') {
                Ext.apply(store.proxy.extraParams, {
                    name: searchText
                });
            }
            if (searchField == 'dept') {
                Ext.apply(store.proxy.extraParams, {
                    dept: searchText
                });
            }
            if (searchField == 'number') {
                Ext.apply(store.proxy.extraParams, {
                    number: searchText
                });
            }
        }
        store.load({
            params: {
                start: 0,
                limit: 25,
                page: 1
            }
        });
    },
    gooutExporterExcel: function (btn) {
        var searchField = this.lookupReference('gooutGridSearchField').getValue();
        var searchText = this.lookupReference('gooutGridSearchText').getValue();
        var searchStartTime = Ext.util.Format.date(this.lookupReference('gooutSearchForm-startTime').getValue(), 'Y-m-d');
        var searchEndTime = Ext.util.Format.date(this.lookupReference('gooutSearchForm-endTime').getValue(), 'Y-m-d');
        var store = Ext.getCmp('gooutQueryGrid').getStore();
        Ext.apply(store.proxy.extraParams, {
            name: '',
            dept: '',
            number: '',
            startTime: '',
            endTime: ''
        });
        if (searchStartTime != '' && searchEndTime != '') {
            if (searchField == 'name') {
                Ext.apply(store.proxy.extraParams, {
                    name: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }
            if (searchField == 'dept') {
                Ext.apply(store.proxy.extraParams, {
                    dept: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }
            if (searchField == 'number') {
                Ext.apply(store.proxy.extraParams, {
                    number: searchText,
                    startTime: searchStartTime,
                    endTime: searchEndTime
                });
            }

        } else {
            if (searchField == 'name') {
                Ext.apply(store.proxy.extraParams, {
                    name: searchText
                });
            }
            if (searchField == 'dept') {
                Ext.apply(store.proxy.extraParams, {
                    dept: searchText
                });
            }
            if (searchField == 'number') {
                Ext.apply(store.proxy.extraParams, {
                    number: searchText
                });
            }

        }
        store.load({
            url: 'goout/exporterExcel',
            callback: function (r, option, success) {
                if (success) {
                    Ext.Msg.alert('操作成功', "操作成功", function () {
                        window.location.reload();
                    });

                } else {
                    Ext.Msg.alert('操作失败', "操作失败");
                }
            }
        });

    }

});
